from typing import List
from pydantic import Field
from pydantic_settings import BaseSettings


class Settings(BaseSettings):
    """应用配置类，使用 pydantic 进行环境变量管理"""
    
    # Flask 基础配置
    flask_env: str = Field(default="development", alias="FLASK_ENV")
    secret_key: str = Field(default="dev-secret-key", alias="SECRET_KEY")
    debug: bool = Field(default=True, alias="DEBUG")
    
    # 数据库配置
    database_url: str = Field(default="sqlite:///app.db", alias="DATABASE_URL")
    
    # JWT 配置
    jwt_secret_key: str = Field(default="jwt-secret-key", alias="JWT_SECRET_KEY")
    jwt_access_token_expires: int = Field(default=3600, alias="JWT_ACCESS_TOKEN_EXPIRES")
    
    # 日志配置
    log_level: str = Field(default="INFO", alias="LOG_LEVEL")
    log_file: str = Field(default="logs/app.log", alias="LOG_FILE")
    
    # 国际化配置
    default_language: str = Field(default="zh", alias="DEFAULT_LANGUAGE")
    languages: str = Field(default="en,zh,ja", alias="LANGUAGES")
    
    # API 配置
    api_title: str = Field(default="Flask Template API", alias="API_TITLE")
    api_version: str = Field(default="v1", alias="API_VERSION")
    openapi_version: str = Field(default="3.0.2", alias="OPENAPI_VERSION")
    
    @property
    def language_list(self) -> List[str]:
        """返回支持的语言列表"""
        return [lang.strip() for lang in self.languages.split(",")]
    
    class Config:
        env_file = ".env"
        env_file_encoding = "utf-8"


# 全局配置实例
settings = Settings() 